<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$this->model('member')->checklogin();
$return['show_setmobile']=cfc('core')->check_setmobile(1);
$return['show_setmember']=cfc('core')->check_setmember(1);
//升级会员：
//$this->model('member')->check_uplevel($_SESSION['uid']);
//注册电商客会员
$item=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','mobile','avatar','nickname'));
$item['id']=$_SESSION['uid'];
$item['mycoupon']=pdo_count('jy_weishop_coupon_getlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
$item['level']=$this->pdo_getcolumn('member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'level');
$item['level'] =$this->pdo_getcolumn('member_level',array('id'=>$item['level'],'uniacid'=>$_SESSION['uniacid']),'title');
$item['level'] = $item['level']?$item['level']:'普通会员';
if($_SESSION['os']=='windows' && $return['pc_set']['no_pc']!=1){
	$return['setting']=$this->plugin_setting('basic');
	$return['member']=$item;
	exi($return);
}else{
	$return['setting']=$this->plugin_setting('setting');
	foreach($return['setting']['footernav'] as &$fv){
		$fv['url']=$fv['action'];
	}
}
$my_days = array(
			array('title'=>'我的优惠券','icon'=>'icon-youhuiquan','color'=>'#cc99ff','action'=>'jy_weishop/coupon.myindex/'),
			array('title'=>'微信会员卡','icon'=>'icon-daifahuo','color'=>'#cc99ff','action'=>'core/member.wxcard/main/'),
			array('title'=>'余额提现','icon'=>'icon-dixiaofei','color'=>'#cc99ff','action'=>'core/member.tixian/'),
			array('title'=>'地址管理','icon'=>'icon-position','color'=>'#cc99ff','action'=>'core/member.address/'),
			array('title'=>'帮助中心','icon'=>'icon-help','color'=>'#cc99ff','action'=>'jy_weishop/news.list/'),
			array('title'=>'获得购物卡','icon'=>'icon-qiangdan','color'=>'#cc99ff','action'=>'jy_weishop/member.getcard/'),
			array('title'=>'我的购物车','icon'=>'icon-gouwuche','color'=>'#cc99ff','action'=>'jy_weishop/member.cart/'),
			array('title'=>'我的购物卡','icon'=>'icon-pingzhengzhongxin','color'=>'#cc99ff','action'=>'jy_weishop/member.mycard/'),
			array('title'=>'我的关注','icon'=>'icon-woguanzhudepinpai','color'=>'#cc99ff','action'=>'jy_weishop/member.favorite/'),
			array('title'=>'我的足迹','icon'=>'icon-zuji','color'=>'#cc99ff','action'=>'jy_weishop/member.history/'),
);
$return['setting']['my_days'] = !empty($return['setting']['my_days']) ? $return['setting']['my_days'] : $my_days;
$my_logs = array(
			array('title'=>'积分日志','icon'=>'icon-jifen','color'=>'#cc99ff','action'=>'core/member.credit_log/list/type=1'),
			array('title'=>'余额日志','icon'=>'icon-jiangjiatongzhi','color'=>'#cc99ff','action'=>'core/member.credit_log/list/type=2'),
			array('title'=>'提现日志','icon'=>'icon-trade','color'=>'#cc99ff','action'=>'core/member.cash_log/'),
			array('title'=>'红包日志','icon'=>'icon-ai-hongbao','color'=>'#cc99ff','action'=>'core/member.red_log/'),
);
$return['setting']['my_logs'] = !empty($return['setting']['my_logs']) ? $return['setting']['my_logs'] : $my_logs;
$my_memberbtn = array(
			array('title'=>'小程序直播','icon'=>'icon-video','color'=>'#cc99ff','action'=>'jy_weishop/sale.live_index/'),
			array('title'=>'领取优惠券','icon'=>'icon-youhuiquan1','color'=>'#cc99ff','action'=>'jy_weishop/coupon.index/'),
			array('title'=>'领取微信会员卡','icon'=>'icon-huiyuanqia','color'=>'#cc99ff','action'=>'core/member.wxcard/main/'),
			array('title'=>'积分排行','icon'=>'icon-paixing','color'=>'#cc99ff','action'=>'jy_weishop/member.rank/'),
);
$install = check_account_permission('jy_commission');
if($install && $_SESSION['current_plugin'] !='jy_friends_shop'){
	$fenxiaoset=plugin('jy_commission')->plugin_setting('page_setting');
	$my_memberbtn[]=array('action'=>'jy_commission/index/','title'=>$fenxiaoset['tcenter']?:'我的分销','icon'=>'icon-paihao0','remark'=>'');
}
$install = check_account_permission('jy_merch');
if($install && $_SESSION['current_plugin'] !='jy_friends_shop'){
	$my_memberbtn[]=array('action'=>'jy_merch/manage.index/','title'=>'商户入口','icon'=>'icon-dianpu','remark'=>'');
}
$install = check_account_permission('jy_giftbao');
if($install && $_SESSION['current_plugin'] !='jy_friends_shop'){
	$my_memberbtn[]=array('action'=>'jy_weishop/sale.mylibao/','title'=>'我的礼包','icon'=>'icon-gifts','remark'=>'');
}
$return['setting']['my_memberbtn'] = !empty($return['setting']['my_memberbtn']) ? $return['setting']['my_memberbtn'] : $my_memberbtn;
$return['item']=$item;
$status0 = pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>0));
$status1 = pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1));
$status2 = pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>2));
$status3 = pdo_count('jy_weishop_order',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>3,'iscomment'=>0));
$return['statics']=array(
	'status0'=>$status0,
	'status1'=>$status1,
	'status2'=>$status2,
	'status3'=>$status3,
);
$wxcard_setting=uni_setting('wx_card_setting');
$wxcard_edit=uni_setting('wx_card_edit');

if($wxcard_edit['card_id'] && $wxcard_edit['status']==1 && $wxcard_setting['open']){
	//存在会员卡且允许领取微信会员卡，检查是否已领卡
	$check=pdo_getcolumn('core_fans',array('openid'=>$_SESSION['openid'],'uniacid'=>$_SESSION['uniacid'],'wxgid'=>$_SESSION['wechat_id']),'wxcard_code');
	if(!$check){
		$wxcard=1;
	}
}
if(!$wxcard){
	array_splice($menu_list,3,1);
}
//判断配送员
$install = check_account_permission('jy_peisong');
if($install){
	$return['is_peisong'] = pdo_getcolumn('jy_peisong_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'id');
}
//判断店员
$return['is_worker'] = pdo_getcolumn('jy_weishop_store_worker',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'id');
$tmplIds=array();
if($return['is_worker']){
	//获取小程序订阅消息ID	
	if($_SESSION['wxapp_id']){
		$tmpid=cfc('wxapp_api')->get_tpl_template_id('3534',[1,2,3,4],'pay2seller','订单支付成功通知卖方','jy_weishop');
		if($tmpid){
			$tmplIds[]=$tmpid;
		}
		$tmpid=cfc('wxapp_api')->get_tpl_template_id('3534',[1,2,3,4],'send2seller','订单发货通知卖方','jy_weishop');
		if($tmpid){
			$tmplIds[]=$tmpid;
		}
		$tmpid=cfc('wxapp_api')->get_tpl_template_id('3534',[1,2,3,4],'receive2seller','订单确认收货通知卖方','jy_weishop');
		if($tmpid){
			$tmplIds[]=$tmpid;
		}	
	}	
}
$return['tmplIds']=$tmplIds;
/*$return['htmls']['list'][]=array('type'=>'menu_list','list'=>$menu_list);
$return['htmls']['list'][]=array('type'=>'submit_list','list'=>array(
	array('url'=>'core/member.cpassword/','title'=>'修改密码'),
	array('url'=>'core/member.logout/','title'=>'退出登陆','title_color'=>'#fff','background'=>'red'),
));*/
$sale_luck=plugin('jy_weishop')->plugin_setting('sale_luck');
if($sale_luck['isopen']==1){
	$return['sale_luck']=model('jy_weishop/activity/sales')->getluck(true);
}
$return['closedsales']=1;
$return['setpay']=uni_setting('pay');
$return['menu_list']=$menu_list;
$return['feemoney']=$this->plugin_setting('feemoney');
if($return['feemoney']['isopen']==1){
	//节省数据
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$monthtime=mktime(0,0,0,date('m'),1,date('Y'));
	$yearstime=strtotime(date("Y",time())."-1"."-1");
	$lastyearstime=strtotime(date("Y",time())."-2"."-1");
	$daysgoods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime >'=>$daytime));
	$return['feemoney_day'] = 0;
	foreach($daysgoods as $dv){
				$status = pdo_getcolumn('jy_weishop_order',array('id'=>$dv['orderid'],'uniacid'=>$_SESSION['uniacid']),'status');
				if($status!=1 && $status!=2 && $status!=3){
					continue;
				}
				$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$dv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','marketprice'));
				$dv['feemoney']=$goodsinfo['marketprice']>0?$goodsinfo['marketprice']-$dv['price']:$return['feemoney']['feerade']*$dv['price']/100;
				$dv['feemoney']=$dv['total']*$dv['feemoney'];
				$return['feemoney_day'] +=$dv['feemoney'];
	}
	$return['feemoney_day']=price($return['feemoney_day']);
	
	$monthgoods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime >'=>$monthtime));
	$return['feemoney_month'] = 0;
	foreach($monthgoods as $dv){
				$status = pdo_getcolumn('jy_weishop_order',array('id'=>$dv['orderid'],'uniacid'=>$_SESSION['uniacid']),'status');
				if($status!=1 && $status!=2 && $status!=3){
					continue;
				}
				$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$dv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','marketprice'));
				$dv['feemoney']=$goodsinfo['marketprice']>0?$goodsinfo['marketprice']-$dv['price']:$return['feemoney']['feerade']*$dv['price']/100;
				$dv['feemoney']=$dv['total']*$dv['feemoney'];
				$return['feemoney_month'] +=$dv['feemoney'];
	}
	$return['feemoney_month']=price($return['feemoney_month']);
	
	$yearsgoods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime >'=>$yearstime));
	$return['feemoney_years'] = 0;
	foreach($yearsgoods as $dv){
				$status = pdo_getcolumn('jy_weishop_order',array('id'=>$dv['orderid'],'uniacid'=>$_SESSION['uniacid']),'status');
				if($status!=1 && $status!=2 && $status!=3){
					continue;
				}
				$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$dv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','marketprice'));
				$dv['feemoney']=$goodsinfo['marketprice']>0?$goodsinfo['marketprice']-$dv['price']:$return['feemoney']['feerade']*$dv['price']/100;
				$dv['feemoney']=$dv['total']*$dv['feemoney'];
				$return['feemoney_years'] +=$dv['feemoney'];
	}
	$return['feemoney_years']=price($return['feemoney_years']);
	
	$lastyearsgoods=pdo_getall('jy_weishop_order_goods',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'createtime between'=>array($yearstime,$lastyearstime)));
	$return['feemoney_lastyears'] = 0;
	foreach($lastyearsgoods as $dv){
				$status = pdo_getcolumn('jy_weishop_order',array('id'=>$dv['orderid'],'uniacid'=>$_SESSION['uniacid']),'status');
				if($status!=1 && $status!=2 && $status!=3){
					continue;
				}
				$goodsinfo = pdo_get('jy_weishop_goods',array('id'=>$dv['goodsid'],'uniacid'=>$_SESSION['uniacid']),array('id','marketprice'));
				$dv['feemoney']=$goodsinfo['marketprice']>0?$goodsinfo['marketprice']-$dv['price']:$return['feemoney']['feerade']*$dv['price']/100;
				$dv['feemoney']=$dv['total']*$dv['feemoney'];
				$return['feemoney_lastyears'] +=$dv['feemoney'];
	}
	$return['feemoney_lastyears']=price($return['feemoney_lastyears']);
}
$current_plugin=$_SESSION['current_plugin']?:'jy_weishop';
if($return['sale_luck']){
		$sharelink=$current_plugin.'/index//fromuser='.$_SESSION['uid'].'&luckkey='.$return['sale_luck']['luckkey'];
		if($sale_luck['share_title']){
			$sale_luck['share_title']=str_replace('[lucktitle]',$return['sale_luck']['title'],$sale_luck['share_title']);
		}
		if($sale_luck['share_desc']){
			$sale_luck['share_desc']=str_replace('[lucktitle]',$return['sale_luck']['title'],$sale_luck['share_desc']);
		}
		$return['sharedata']=array(
			'title'=>$sale_luck['share_title']?$sale_luck['share_title']:'我今日运势《'.$return['sale_luck']['title'].'》，快来借势吧,好运势享大折扣！',
			'desc'=>$sale_luck['share_desc']?$sale_luck['share_desc']:'拥有好运势，不仅仅拥有好心情，更能享受好的购物折扣哦！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>$sale_luck['share_image']?tomedia($sale_luck['share_image']):tomedia('../addons/jy_weishop/resource/images/sales/luck_share_image.jpg')
		);
}else{
		$sharelink=$current_plugin.'/index//fromuser='.$_SESSION['uid'];
		$return['sharedata']=array(
			'title'=>$setting['share_title']?$setting['share_title']:'首页-在线商城',
			'desc'=>$setting['share_desc']?$setting['share_desc']:'在线商城，一个属于自己的个人商城！',
			'link'=>custom_url($sharelink,true),
			'imgUrl'=>ATTACHMENT_URL.$setting['share_image']
		);
}
set_html('title','会员中心');
exi($return);	
?>